* Figure B.13
* 29 Oct 2021

clear all
set more off

grstyle init
grstyle set plain, nogrid horizontal
grstyle color background white

*Choose figure width:
local fig_w= 5
local res = `fig_w' * 600

* Figure B.13 panel a) 

import delimited "$intermediate\counterfactuals\Simulate_increase_k_by_multiples_of_avg_pce_results.csv", clear

rename var1 perc
label variable perc "Value of transfer (% of STUP PCE)"
rename var4 value
replace value = value/(10^6)
label variable value "Total value of transfer"
replace misallocation_summary = misallocation_summary/(10^6)
label variable misallocation_summary "Total value of misallocation"

*Colored version
twoway (line value perc) (line misallocation_summary perc), legend(r(2) ring(0) pos(2)) ytitle("Millions of BDT") yla(#7) xla(#9) xtitle(, margin(t+2)) name(count1, replace) 
graph save count1 "$output/misall_transfer.gph", replace
graph export "$output/misall_transfer.png", as(png) replace

*TIFF Greyscale version
twoway (line value perc, lcol(black)) (line misallocation_summary perc, lcol(gs10)), legend(r(2) ring(0) pos(2)) ytitle("Millions of BDT") yla(#7) xla(#9) xtitle(, margin(t+2)) name(count1, replace) xsize(`fig_w')
graph export "$output/TIFF/misall_transfer.tif", as(tif) replace width(`res')


* Figure B.13 panel b)

import delimited "$intermediate\counterfactuals\Simulate_increase_k_by_multiples_of_avg_pce_misall_vs_kstar_results.csv", clear

rename var1 perc
label variable perc "Value of transfer (% of STUP PCE)"
rename var4 value
replace value = value/(10^6)
label variable value "Total value of transfer"
replace misallocation_summary = misallocation_summary/(10^6)
label variable misallocation_summary "Total value of misallocation"

*Colored version
twoway (line value perc) (line misallocation_summary perc), legend(r(2) ring(0) pos(2)) ytitle("Millions of BDT") yla(#7) xla(#9) xtitle(, margin(t+2)) name(count2, replace) 
graph save count2 "$output/misall_transfer2.gph", replace
graph export "$output/misall_transfer2.png", as(png) replace

*TIFF greyscale version:
twoway (line value perc, lcol(black)) (line misallocation_summary perc, lcol(gs10)), legend(r(2) ring(0) pos(2)) ytitle("Millions of BDT") yla(#7) xla(#9) xtitle(, margin(t+2)) name(count2, replace) xsize(`fig_w')
graph export "$output/TIFF/misall_transfer2.tif", as(tif) replace width(`res')
